package com.example.demo.common;

import org.apache.commons.lang3.StringUtils;

public final class ParametersUtil {

    private ParametersUtil() {

    }
    //rand=123&userName=eeee
    public static String parseParameters(String query, String key) {
        if(StringUtils.isNotEmpty(query) && StringUtils.isNotEmpty(key)) {
            int posAnd = query.indexOf("&");
            if(posAnd != -1) {
                String [] params = query.split("&");
                for(String param: params) {
                    String [] values = param.split("=");
                    if(key.equals(values[0])) {
                        return values[1];
                    }
                }
            } else {
                String [] values = query.split("=");
                if(key.equals(values[0])) {
                    return values[1];
                }
            }
        }

        return null;
    }
}
